package at.jsug.topicvoting.gwt1.client.view;

import at.jsug.topicvoting.gwt1.client.App;
import at.jsug.topicvoting.gwt1.client.logic.event.NewTopicEvent;
import at.jsug.topicvoting.gwt1.client.remote.DummyDataFacade;
import at.jsug.topicvoting.gwt1.client.view.table.TopicsTable;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MainWindow extends VerticalPanel {

	public MainWindow() {
		this.setWidth("100%");
		this.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
	    
		final TopicsTable topicsGrid = new TopicsTable(App.DATA_FACADE);
		topicsGrid.setWidth("100%");
		topicsGrid.setHeight("100%");
		
		this.add(this.newControlBar());
		this.add(topicsGrid);
	}
	
	private Widget newControlBar() {
		final HorizontalPanel controlBar = new HorizontalPanel();
		controlBar.setWidth("100%");
		controlBar.setHorizontalAlignment(VerticalPanel.ALIGN_LEFT);

		
		final Button btnNewTopic = new Button();
		btnNewTopic.setText("New Topic ...");
		btnNewTopic.addClickListener(new ClickListener() { public void onClick(Widget sender) { new NewTopicEvent().dispatch(); }});
		controlBar.add(btnNewTopic);
		
		new DelmeRest(controlBar);
		
		
		return controlBar;
	}
	
}
